<template>
	<div>
		<my-header :header="header"></my-header>
		<div class="form">
			<div class="error">
			</div>
			<div class="row-1">
				<div class="label">
					<label>推广人员</label>
				</div>
				<div class="info">
					<label>{{user.customer_name}}</label>
				</div>
			</div>
			<div class="row-1">
				<div class="label">
					<label>备注</label>
				</div>
				<div class="textarea">
					<textarea placeholder="note:" maxlength="200" v-model.trim="comment"></textarea>
				</div>
			</div>
			<div class="button submit">
				<div v-show="!isConfirm" v-on:click="confirm(true)">
					提交
				</div>
				<div class="loading" v-show="isConfirm">
					<img src="../assets/img/loading@3x.png" />
				</div>
			</div>
			<div class="button skip">
				<div v-on:click="confirm(false)">
					跳过
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import myHeader from "../components/my-header";
import $ from "../assets/js/jquery.min.js";
import { mapState, mapActions } from "vuex";
import { USER_SIGNIN } from "../store/user";

export default {
  name: "remark",
  data() {
    return {
      header: {
        cnTitle: "备注",
        enTitle: "Tips",
        cnStyle: {
          fontSize: "32px",
          marginTop: "15px"
        },
        enStyle: {
          fontSize: "18px"
        }
      },
      comment: "",
      isConfirm: false
    };
  },
  created: function() {
    // var _that = this;
    // if(_that.user.token==undefined) {
    //   _that.$router.push('/login');
    // }
  },

  methods: {
    ...mapActions([USER_SIGNIN]),
    confirm: function(needComment) {
      var _that = this;
      var comment = _that.comment;
      if (!needComment) {
        _that.$router.push("/success");
      } else {
        if (comment == "") {
          alert("请输入备注");
        } else {
          //var url = 'http://192.168.87.162:80/VmdService.Host.OpenService/OMSaveLeadCommentRequest';
          //var urlroot = API_ROOT;
          var urlroot = urlchange;
          var url = urlroot + "/OMSaveLeadCommentRequest";
          this.isConfirm = true;
          $.ajax({
            type: "GET",
            url: url,
            dataType: "jsonp",
            data: {
              key: "omsaveleadcomment",
              /*"parameters": "token=" + _that.user.token + "&leadsn=" + _that.user.lead_sn + "&comment=" + comment,*/
              ContentType: "application/x-www-form-urlencoded",
              fun: "callbackFun",
              //"token": "z6fYujYV/QAKehzfyAI8ZxAVWto="
              token: _that.user.token,
              //"token": "465y5",
              LeanSn: _that.user.lead_sn,
              RecordNote: comment,
              ClientIp: ""
            },
            jsonpCallback: "callbackFun",
            success: function(result) {
              _that.isConfirm = false;
              //var jsonResult = JSON.parse(result)[0];
              var jsonResult = result.ResultInfo;
              if (jsonResult.msgcode >= 0) {
                // _that.user.todaycount = jsonResult.todaycount;
                // _that.USER_SIGNIN(_that.user)
                _that.$router.push("/success");
              } else {
                alert("操作失败");
              }

              _that.isConfirm = false;
            },

            error: function(error) {
              alert("系统异常");
              _that.isConfirm = false;
            }
          });
        }
      }
    }
  },
  computed: { ...mapState(["user"]) },
  components: { myHeader }
};
</script>
